package schema

import (
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/index"
)

// MessageReadStatus holds the schema definition for the MessageReadStatus entity.
type MessageReadStatus struct {
	ent.Schema
}

// Fields of the MessageReadStatus.
func (MessageReadStatus) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id").
			Positive().
			Unique().
			Immutable().
			Comment("已读状态ID"),
		field.Int64("message_id").
			Comment("消息ID"),
		field.Int64("user_id").
			Comment("用户ID"),
		field.Time("read_at").
			Default(time.Now).
			Comment("已读时间"),
	}
}

// Edges of the MessageReadStatus.
func (MessageReadStatus) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("message", Message.Type).
			Ref("read_statuses").
			Field("message_id").
			Unique().
			Required().
			Comment("已读消息"),
		edge.From("user", User.Type).
			Ref("read_statuses").
			Field("user_id").
			Unique().
			Required().
			Comment("已读用户"),
	}
}

// Indexes of the MessageReadStatus.
func (MessageReadStatus) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("message_id", "user_id").
			Unique(),
		index.Fields("user_id"),
	}
}

// Annotations of the MessageReadStatus.
func (MessageReadStatus) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{
			Table: "message_read_status",
		},
	}
}
